package com.cn.steam.iam.controller.open;

import com.cn.steam.iam.model.vo.EngineeringCompany;
import com.cn.steam.iam.model.vo.OnBehalfSslReq;
import com.cn.steam.iam.model.vo.OnBehalfSslRes;
import com.cn.steam.iam.service.ExtClientUserProfileService;
import com.cn.steam.iam.service.IamPrivilegeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

import static com.cn.steam.foundation.common.model.CommonConstant.OPEN_PRIVILEGE_V1_API;
/**
 * @author: zjm
 * @create: 2021-11-20 21:48
 **/
@RestController
@RequestMapping(OPEN_PRIVILEGE_V1_API)
public class IamPrivilegeController {
    @Autowired
    private IamPrivilegeService iamPrivilegeService;

    @Autowired
    private ExtClientUserProfileService extClientUserProfileService;

    //todo
    @Value("${jixie.partnerId:STEAM-XXX-119}")
    private String steamPartnerId;


    @PreAuthorize("hasAuthority('PARTNER_PRIVILEGE_PERMISSION_ONBEHALF_SSL')")
    @PostMapping("/on-behalf-ssl")
    public OnBehalfSslRes OnBehalfSsl(@Valid @RequestBody OnBehalfSslReq sslReq){

        return iamPrivilegeService.generateSslCode(sslReq);
    }

    @PreAuthorize("hasAuthority('')")
    @PostMapping("/register-ssl-user/zzb")
    public OnBehalfSslRes registerSslUserZzb(@RequestBody EngineeringCompany engineeringCompany,String sslUserId){
//        String sslUserId = zzbInternalService.createEngineeringCompany(engineeringCompany);
        extClientUserProfileService.addClientUserMappingForSsl(steamPartnerId, sslUserId);
        OnBehalfSslRes onBehalfSslRes = new OnBehalfSslRes();
        onBehalfSslRes.setSslId(sslUserId);
        return onBehalfSslRes;
    }
}
